<div class="row">
    <div class="col-md-12">
        <h4 class="pv-xxs pr-xxs text-primary">
            Analysis
            <span class="pull-right" ng-if="analysisEnabled">
                <small><a href class="text-primary" ng-click="runAll()">Run all</a></small>
            </span>
        </h4>
        <table class="table table-striped">
            <thead>
                <th>Analyzer</th>
                <th width="450">Last analysis</th>
                <th width="60" class="text-center" ng-if="analysisEnabled">Actions</th>
            </thead>
            <tbody>
                <tr ng-repeat="(analyzerName, jobs) in analyzerJobs"
                    ng-init="analyzer=analyzers[analyzerName]; analyzers[analyzerName].showRows=false;">
                    <td>
                        <a ng-if="jobs.length > 1" class="noline mr-xxs" href ng-click="analyzers[analyzerName].showRows = !analyzers[analyzerName].showRows">
                            <i class="fa" ng-class="{ true:'fa-minus-square-o', false:'fa-plus-square-o' }[analyzers[analyzerName].showRows]"></i>
                        </a>
                        <span uib-tooltip="{{analyzer.description}}" tooltip-placement="right">{{analyzer.name || jobs[0].analyzerName}}</span>
                        <!--pre>
                          analyzer = {{analyzer}}
                          analyzers = {{analyzers}}
                          jobs = {{jobs}}
                        </pre-->
                        <!-- <div class="text-muted">{{}}</div> -->
                    </td>
                    <!-- <td>
                        <ul class="list-unstyled">
                            <li ng-repeat="cortexId in analyzer.cortexIds">{{cortexId}}</li>
                        </ul>
                    </td> -->
                    <td>
                        <ul class="list-unstyled">
                            <li ng-if="jobs.length === 0"><em>None</em></li>
                            <li ng-repeat="job in jobs" ng-show="analyzer.showRows || $first">
                                <span class="mr-s">
                                    <i class="glyphicon" ng-class="{ Failure:'glyphicon-warning-sign text-warning', Success:'glyphicon-ok text-success', InProgress:'fa fa-cog fa-spin'}[job.status]"></i>
                                </span>

                                <a href ng-click="showReport(job.id)" uib-tooltip="View report">{{(job.endDate || job.startDate) | showDate}}</a> ({{job.cortexId}})
                            </li>
                        </ul>
                    </td>
                    <td ng-if="analysisEnabled" class="text-center">
                        <!-- <pre>{{cortexServers | json}}</pre> -->
                        <span class="btn btn-xs" ng-class="{true: 'btn-warning', false: 'btn-danger'}[jobs.length > 0]"
                            ng-click="runAnalyzer(analyzerName)"
                            ng-if="analyzer.cortexIds.length === 1 && analyzer.active">
                            <i class="glyphicon" ng-class="{true: 'glyphicon-repeat', false: 'glyphicon-fire'}[jobs.length > 0]"></i>
                        </span>

                        <div class="btn-group" ng-if="analyzer.cortexIds.length > 1 && analyzer.active" uib-dropdown>
                            <button type="button" class="btn btn-xs dropdown-toggle"
                                ng-class="{true: 'btn-warning', false: 'btn-danger'}[jobs.length > 0]"
                                uib-dropdown-toggle>
                                <span class="mr-xxxs">
                                    <i class="glyphicon" ng-class="{true: 'glyphicon-repeat', false: 'glyphicon-fire'}[jobs.length > 0]"></i>
                                </span>
                                <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu align-right" uib-dropdown-menu>
                                <li ng-repeat="srv in cortexServers" ng-if="analyzer.cortexIds.indexOf(srv.name) !== -1">
                                    <a href ng-click="runAnalyzer(analyzerName, srv.name)" ng-disabled="srv.status === 'ERROR'">
                                        <div>
                                            <strong>{{srv.name}}</strong>
                                        </div>
                                        <div>
                                            <strong ng-class="{'OK': 'text-success', 'ERROR': 'text-danger'}[srv.status]">Status: {{srv.status}}</strong>
                                        </div>
                                    </a>
                                </li>
                            </ul>
                        </div>

                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>

<div class="row" id="analysis-report">
    <div class="col-md-6 col-md-offset-3">
        <hr>
    </div>
</div>

<div class="row observable-report" ng-if="report">
    <div class="col-md-12">
        <h4 class="pad10 text-primary">
            Report <small>for {{report.template}} analysis of {{(report.endDate || report.startDate) | showDate}}</small>
            <span class="pull-right">
                <small><a href class="text-primary" ng-click="showRaw = !showRaw">{{showRaw ? 'Hide': 'Show'}} Raw Report</a></small>
                <small class="mh-xxxs">|</small>
                <small><a href class="text-primary" ng-click="showArtifacts = !showArtifacts">{{showArtifacts ? 'Hide': 'Show'}} observables ({{report.content.artifacts.length}})</a></small>
            </span>
        </h4>
        <div ng-if="showArtifacts" class="">
            <div class="panel panel-info">
                <div class="panel-heading">
                    <strong>Observables</strong> <small>Extracted from analysis report</small>
                </div>
                <div class="panel-body">
                    <report-observables origin="artifact" case-id="caseId" observables="report.content.artifacts" analyzer="report.template"></report-observables>
                </div>
            </div>
        </div>
        <div ng-if="showRaw">
            <div class="panel" ng-class="{'panel-info': report.content.success, 'panel-danger': !report.content.success}">
                <div class="panel-heading">
                    <strong>Raw report</strong>
                </div>
                <div class="panel-body">
                    <pre>{{(report.content.full || report.content) | json}}</pre>
                </div>
            </div>
        </div>
        <report ng-if="!showRaw" artifact="artifact"
            content="report.content.full || report.content"
            default="jsonhuman"
            report-type="long"
            name="report.template"
            status="report.status"
            success="report.content.success"
            ></report>
    </div>
</div>
